/**
 * 好大夫
 * 根据二级科室采集疾病名称
 * @type {exports}
 */
module.exports = class {
  constructor(page) {
    this.model = think.model("puppeteer");
    this.page = page;
  }
  async evaluate() {
    const { page } = this;
    const list = await page.evaluate(() => {
      const items = document.querySelectorAll(".m_box_green .ct a");
      const list = [];
      // eslint-disable-next-line no-undef,no-unused-vars
      for (const item of items) {
        // eslint-disable-next-line no-undef
        list.push({
          name: item.textContent,
          href: item.href
        });
      }
      return list;
    });
    return list;
  }
  async post(data, cate) {
    for (let i = 0; i < data.length; i++) {
      const item = data[i];
      console.log(item);
      await this.model.thenAdd(
        {
          cate: cate.name,
          name: item.name,
          url: item.href,
          module: "HaodfJibingDetail"
        },
        { url: item.href }
      );
    }
  }
};
